package com.ss.ttm.player;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;

import com.ss.ttm.net.AVResolver;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import inline.ScreenshotListener;

public class TTPlayerClient extends MediaPlayerClient implements Handler.Callback, SurfaceLifecycleCallback {
    private static final String TAG = TTPlayerClient.class.getSimpleName();
    private String mBufferingInfo;
    private SurfaceLifecycleCallbackProxy mCallback;
    private Context mContext;
    private int mCrashType;
    private StringBuilder mCrashedInfo;
    private int mErrorCode;
    private Handler mHandler;
    private final Object mHandlerLocker;
    private long mListenerState;
    private LinkedList mLogInfo;
    private a mLogListener$2f9df788;
    private IMediaPlayerClient.OnBufferingUpdateListener mOnBufferingUpdateListener;
    private IMediaPlayerClient.OnCompletionListener mOnCompletionListener;
    private IMediaPlayerClient.OnErrorListener mOnErrorListener;
    private ScreenshotListener mOnExternInfoListener$6e9041bc;
    private IMediaPlayerClient.OnInfoListener mOnInfoListener;
    private IMediaPlayerClient.OnPreparedListener mOnPreparedListener;
    private IMediaPlayerClient.OnSeekCompleteListener mOnSeekCompleteListener;
    private IMediaPlayerClient.OnVideoSizeChangedListener mOnVideoSizeChangedListener;
    private int mPlayLifeId;
    private com.ss.ttm.player.f mPlayer;
    private final ReentrantReadWriteLock.ReadLock mReadLock;
    private final ReentrantReadWriteLock mReadWritedLock;
    private volatile boolean mRealsedSurface;
    private final ReentrantLock mReentrantLock;
    private boolean mScreenOnWhilePlaying;
    private boolean mSeekComplete;
    private boolean mStayAwake;
    private Surface mSurface;
    private SurfaceHolder mSurfaceHolder;
    private String mUri;
    private String mVoiceInfo;
    private PowerManager.WakeLock mWakeLock;
    private IMediaPlayerClient mWrapper;
    private final ReentrantReadWriteLock.WriteLock mWriteLock;

    private TTPlayerClient(Context arg5) {
        this.mSeekComplete = true;
        this.mLogInfo = new LinkedList();
        this.mListenerState = 0;
        this.mRealsedSurface = false;
        this.mPlayLifeId = -1;
        this.mHandlerLocker = new Object();
        this.mReentrantLock = new ReentrantLock();
        this.mReadWritedLock = new ReentrantReadWriteLock();
        this.mReadLock = this.mReadWritedLock.readLock();
        this.mWriteLock = this.mReadWritedLock.writeLock();
        this.mErrorCode = 0;
        this.mCrashedInfo = new StringBuilder(1024);
        this.mCrashType = -1;
        this.mRealsedSurface = false;
        this.mCallback = new SurfaceLifecycleCallbackProxy(((SurfaceLifecycleCallback) this));
        this.mContext = arg5;
        this.mHandler = Looper.myLooper() != null ? new Handler(((Handler.Callback) this)) : new Handler(Looper.getMainLooper(), ((Handler.Callback) this));
    }

    public void close() {
        this.mRealsedSurface = true;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.close();
            }
        } catch (Throwable throwable) {
            this.mReadLock.unlock();
            throw throwable;
        }

        this.mReadLock.unlock();
    }

    public static TTPlayerClient create(IMediaPlayerClient arg3, Context arg4) {
        com.ss.ttm.player.f v2;
        TTPlayerClient v0_1;
        Class v1 = TTPlayerClient.class;
        synchronized (v1) {
            v0_1 = new TTPlayerClient(arg4);
            v2 = com.ss.ttm.player.f.a(arg4, v0_1);
            if (v2 == null) {
                return null;
            } else {
                v0_1.mPlayer = v2;
                v0_1.mWrapper = arg3;
                return v0_1;
            }
        }
    }

    public int getCurrentPosition() {
        int v0 = 0;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v0 = this.mPlayer.getIntOption(2, 0);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        return v0;
    }

    public String getDataSource() {
        return this.mUri;
    }

    public int getDuration() {
        int v0 = 0;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v0 = this.mPlayer.getIntOption(1, 0);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        return v0;
    }

    public int getIntOption(int arg3, int arg4) {
        if (arg3 == 5000) {
            arg4 = this.mErrorCode;
        } else if (arg3 == 26) {
            arg4 = this.mCrashType;
        } else {
            this.mReadLock.lock();
            try {
                if (this.isValid()) {
                    arg4 = this.mPlayer.getIntOption(arg3, arg4);
                }
            } catch (Throwable v0) {
                this.mReadLock.unlock();
                throw v0;
            }

            this.mReadLock.unlock();
        }

        return arg4;
    }

    public long getLongOption(int arg3, long arg4) {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                arg4 = this.mPlayer.getLongOption(arg3, arg4);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
        return arg4;
    }

    private String getPlayerCrashedInfo() {
        String v0;
        int v7 = 5;
        int v6 = -1;
        int v2 = m.a(18, 1);
        StringBuilder stringBuilder = new StringBuilder();
        Context v1 = this.mPlayer == null ? this.mContext : this.mPlayer.i();
        if (v1 == null) {
            v0 = "context is null";
        } else {
            if (v2 > 1) {
                String v4 = android.support.design.a.C(v1);
                if (v4 != null) {
                    v0 = android.support.design.a.a(v1, v4, stringBuilder);
                    if (v0 != null) {
                        android.support.design.a.B(v4);
                        this.mCrashType = 1;
                        if (m.a(v7)) {
                            Log.i("ttplayer", "<TTPlayerIPClient,getCrashedInfo>find breakpad file");
                        } else {
                        }

                        return v0;
                    }
                }

                android.support.design.a.a(v1, stringBuilder);
            }

            String v1_1 = m.a(19, null);
            if (v1_1 != null) {
                v0 = android.support.design.a.a(this.mContext, v1_1, stringBuilder);
                if (v0 != null) {
                    android.support.design.a.B(v1_1);
                    this.mCrashType = 1;
                    if (m.a(v7)) {
                        Log.i("ttplayer", "<TTPlayerIPClient,getCrashedInfo>find breakpad file");
                    } else {
                    }

                    return v0;
                }
            }

            stringBuilder.append("\ncreate time:" + android.support.design.a.w());
            stringBuilder.append("\nport version:").append(v2);
            stringBuilder.append("\nstart service info:").append(m.a(16, "not find service start info"));
            stringBuilder.append("\nstop service info:").append(m.a(12, "not find service stop info"));
            stringBuilder.append("\ncrash:").append(m.a(7));
            stringBuilder.append("\nsdk info:").append(m.a(15, "not find sdk info"));
            stringBuilder.append("\ntimeout count:").append(m.a(10, v6));
            stringBuilder.append("\nforeground:").append(m.a(21, v6));
            stringBuilder.append("\non screen:").append(m.a(22, v6));
            stringBuilder.append("\n battery info:").append(m.a(23, "not find"));
            stringBuilder.append("\nurl:").append(this.mUri);
            stringBuilder.append("\ncrash:\r\n").append(this.mCrashedInfo);
            this.mCrashType = 0;
            if (v2 > 1) {
                if (m.a(v7)) {
                    Log.i("ttplayer", "<TTPlayerIPClient,getCrashedInfo>" + stringBuilder.toString());
                }

                return android.support.design.a.C(stringBuilder.toString());
            }

            v0 = stringBuilder.toString();
        }

        return v0;
    }

    private String getPlayerErrorInfo() {
        String v1 = null;
        try {
            StringBuilder v2 = new StringBuilder();
            if (this.mLogInfo != null && this.mLogInfo.size() > 0 || (this.mBufferingInfo != null || this.mVoiceInfo != null)) {
                android.support.design.a.a(this.mContext, v2, "error", "play error");
                Iterator v3 = this.mLogInfo.iterator();
                while (v3.hasNext()) {
                    v2.append(v3.next()).append("\n");
                }

                if (this.mBufferingInfo != null) {
                    v2.append(this.mBufferingInfo).append("\n");
                    this.mBufferingInfo = null;
                }

                if (this.mVoiceInfo == null) {
                } else {
                    v2.append(this.mVoiceInfo).append("\n");
                    this.mVoiceInfo = null;
                }
            }
            String v0_1 = v2.toString();
            return v0_1;
        } catch (Exception v0) {
            return v1;
        }
    }

    public String getStringOption(int arg3) {
        String v0 = null;
        if (arg3 == 5001) {
            v0 = this.getPlayerCrashedInfo();
        } else if (arg3 != 5002) {
            this.mReadLock.lock();
            try {
                if (this.isValid()) {
                    v0 = this.mPlayer.getStringOption(arg3);
                }
            } catch (Throwable v0_1) {
                this.mReadLock.unlock();
                throw v0_1;
            }

            this.mReadLock.unlock();
        } else if (this.mLogInfo != null && this.mLogInfo.size() != 0) {
            v0 = this.getPlayerErrorInfo();
        }

        return v0;
    }

    public int getType() {
        int v0 = 0;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v0 = this.mPlayer.j();
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        return v0;
    }

    public int getVideoHeight() {
        int v0 = 0;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v0 = this.mPlayer.getIntOption(4, 0);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        return v0;
    }

    public int getVideoType() {
        int v0 = 0;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v0 = this.mPlayer.getIntOption(11, 0);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        return v0;
    }

    public int getVideoWidth() {
        int v0 = 0;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v0 = this.mPlayer.getIntOption(3, 0);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        return v0;
    }

    public boolean handleMessage(Message arg5) {
        String v0_1;
        int v1 = arg5.arg2;
        int v2 = arg5.what;
        int v3 = arg5.arg1;
        if ((arg5.obj instanceof String)) {
            v0_1 = (String) arg5.obj;
        } else {
            v0_1 = null;
        }
        this.handleNotify(v1, v2, v3, v0_1);
        return true;
    }

    public void handleNotify(int arg5, int arg6, int arg7, String arg8) {
        int v1 = -2139062143;
        switch (arg6) {
            case 0: {
                this.stayAwake(false);
                if (arg7 == -499989) {
                    m.a(8, true);
                }

                this.sendSeekCompleted(arg5);
                this.sendErrorInfo(this.mErrorCode, arg5);
                break;
            }
            case 2: {
                if (this.mOnPreparedListener == null) {
                    return;
                }

                this.mOnPreparedListener.onPrepared();
                break;
            }
            case 3: {
                if (this.mOnBufferingUpdateListener == null) {
                    return;
                }

                this.mOnBufferingUpdateListener.onBufferingUpdate(arg7);
                break;
            }
            case 6: {
                if (this.mOnVideoSizeChangedListener == null) {
                    return;
                }

                this.mOnVideoSizeChangedListener.onVideoSizeChanged(65535 & arg7, arg7 >> 16);
                break;
            }
            case 4:
            case 5:
            case 7:
            case 8:
            case 9:
            case 10: {
                this.notifyInfo(arg6);
                break;
            }
            case 12: {
                this.sendSeekCompleted(arg5);
                break;
            }
            case 13: {
                this.stayAwake(false);
                this.sendSeekCompleted(arg5);
                this.sendCompletioned(arg5);
                break;
            }
            case 19: {
            }
            case 20000: {
                if (this.mErrorCode == v1) {
                    return;
                }

                this.mErrorCode = v1;
                this.mWriteLock.lock();
                try {
                    com.ss.ttm.player.f v0_1 = this.mPlayer;
                    if (v0_1 == null) {
                        this.mWriteLock.unlock();
                        break;
                    }

                    this.mPlayer = null;
                    v0_1.n();
                } catch (Throwable v0) {
                    this.mWriteLock.unlock();
                    throw v0;
                }

                this.mWriteLock.unlock();
                m.a(7, true);
                this.stayAwake(false);
                this.sendSeekCompleted(arg5);
                this.sendErrorInfo(this.mErrorCode, arg5);
                this.sendCompletioned(arg5);
                return;
            }
        }
    }

    public boolean isLooping() {
        this.mReadLock.lock();
        try {
            if (!this.isValid()) {
                return false;
            } else if (this.mPlayer.getIntOption(5, 0) != 1) {
                return false;
            }
            return false;
        } finally {
            this.mReadLock.unlock();
        }
    }

    public boolean isMute() {
        boolean v0 = true;
        this.mReadLock.lock();
        try {
            if (!this.isValid()) {
                return false;
            } else if (this.mPlayer.getIntOption(12, 0) != 1) {
                return false;
            }
            return true;
        } finally {
            this.mReadLock.unlock();
        }
    }

    public boolean isPlaying() {
        boolean v0 = true;
        this.mReadLock.lock();
        try {
            if (!this.isValid()) {
                return false;
            } else if (this.mPlayer.getIntOption(6, 0) != 1) {
                return false;
            }
            return true;
        } finally {
            this.mReadLock.unlock();
        }
    }

    private boolean isValid() {
        return this.mPlayer != null && this.mPlayer.k();
    }

    public void mouseEvent(int arg3, int arg4, int arg5) {
        int v0 = 0;
        switch (arg3) {
            case 0: {
                v0 = 1;
                break;
            }
            case 1: {
                v0 = 3;
                break;
            }
            case 2: {
                v0 = 2;
                break;
            }
        }

        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.mouseEvent(v0, arg4, arg5);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
    }

    private void notifyInfo(int arg3) {
        if (this.mOnInfoListener != null) {
            int v0 = -1;
            switch (arg3) {
                case 4: {
                    v0 = 701;
                    break;
                }
                case 5: {
                    v0 = 702;
                    break;
                }
                case 7: {
                    v0 = 3;
                    break;
                }
                case 8: {
                    v0 = 801;
                    break;
                }
                case 9: {
                    v0 = 802;
                    break;
                }
                case 10: {
                    v0 = 901;
                    break;
                }
            }

            this.mOnInfoListener.onInfo(v0);
        }
    }

    protected void onCrashedInfo(String arg3) {
        if (this.mCrashedInfo.length() < 1024) {
            this.mCrashedInfo.append(arg3).append("\n");
        }
    }

    protected void onPlayLogInfo(int arg3, int arg4, String arg5) {
        if (arg3 != 2) {
            if (arg3 == 0) {
                this.mErrorCode = arg4;
            }

            if (arg5 == null) {
                return;
            }

            if (this.mLogInfo.size() > 40) {
                this.mLogInfo.removeFirst();
            }

            this.mLogInfo.addLast(arg5);
        } else if (arg4 == 1) {
            this.mVoiceInfo = arg5;
        } else if (arg4 == 0) {
            this.mBufferingInfo = arg5;
        }
    }

    public void onPlayerNotify(int arg3, int arg4, int arg5, String arg6) {
        Object v1 = this.mHandlerLocker;
        synchronized (v1) {
            if (this.mHandler == null) {
            } else {
                Message v0_1 = this.mHandler.obtainMessage(arg4, arg5, arg3);
                v0_1.obj = arg6;
                v0_1.sendToTarget();
            }
        }
    }

    public void onSurfaceChanged(SurfaceHolder surfaceHolder) {
        if (!this.mRealsedSurface) {
            this.mReadLock.lock();
            try {
                if (this.isValid()) {
                    if (surfaceHolder != this.mSurfaceHolder) {
                        this.mSurfaceHolder.removeCallback(this.mCallback);
                        this.mSurfaceHolder = surfaceHolder;
                        this.mSurfaceHolder.addCallback(this.mCallback);
                    }

                    this.mPlayer.setVideoSurface(surfaceHolder.getSurface());
                }
            } catch (Throwable v0) {
                this.mReadLock.unlock();
                throw v0;
            }

            this.mReadLock.unlock();
        }
    }

    public void onSurfaceCreated(SurfaceHolder surfaceHolder) {
    }

    public void onSurfaceDestroyed(SurfaceHolder surfaceHolder) {
        if (!this.mRealsedSurface) {
            this.mReadLock.lock();
            try {
                if (this.isValid()) {
                    this.mPlayer.setVideoSurface((Surface) null);
                }
            } catch (Throwable v0) {
                this.mReadLock.unlock();
                throw v0;
            }

            this.mReadLock.unlock();
        }
    }

    public void pause() {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.pause();
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
        this.stayAwake(false);
    }

    public void prepare() {
        this.prepareAsync();
    }

    public void prepareAsync() {
        if (this.mUri == null) {
            throw new IllegalStateException("not set url.");
        }

        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mErrorCode = 0;
                this.mLogInfo.clear();
                if (this.mRealsedSurface) {
                    this.mPlayer.setVideoSurface(this.mSurfaceHolder.getSurface());
                    this.mRealsedSurface = false;
                }

                this.mPlayer.prepare();
                this.updateLifeId();
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void prevClose() {
        this.mRealsedSurface = true;
        if (this.mSurfaceHolder != null) {
            this.mSurfaceHolder.removeCallback(this.mCallback);
        }

        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.prevClose();
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
        this.mSurface = null;
    }

    public void release() {
        SurfaceHolder v3 = null;
        this.stayAwake(false);
        this.updateSurfaceScreenOn();
        this.mWriteLock.lock();
        try {
            com.ss.ttm.player.f v0_1 = this.mPlayer;
            this.mPlayer = null;
            this.mPlayLifeId = -1;
            if (v0_1 != null) {
                v0_1.release();
            }
        } catch (Throwable v0) {
            this.mWriteLock.unlock();
            throw v0;
        }

        this.mWriteLock.unlock();
        if (this.mSurfaceHolder != null) {
            this.mSurfaceHolder.removeCallback(this.mCallback);
            this.mSurfaceHolder = v3;
            this.mRealsedSurface = true;
        }

        this.mSurface = ((Surface) v3);
        Object v1 = this.mHandlerLocker;
        synchronized (v1) {
            this.mHandler.removeCallbacksAndMessages(null);
            this.mHandler = null;
        }

        if (this.mLogListener$2f9df788 != null) {
            String v0_2 = this.getPlayerErrorInfo();
            if (v0_2 != null) {
                v0_2.length();
            }
        }

        this.mContext = ((Context) v3);
    }

    public void reset() {
        this.mWriteLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.reset();
                if (this.mSurfaceHolder != null) {
                    this.mPlayer.setVideoSurface(this.mSurfaceHolder.getSurface());
                }

                this.mHandler.removeCallbacksAndMessages(null);
                this.mErrorCode = 0;
                this.mLogInfo.clear();
                this.updateLifeId();
            }
        } catch (Throwable v0) {
            this.mWriteLock.unlock();
            throw v0;
        }

        this.mWriteLock.unlock();
    }

    public void rotateCamera(float arg3, float arg4) {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.rotateCamera(arg3, arg4);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void seekTo(int arg3) {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mSeekComplete = false;
                this.mPlayer.seekTo(arg3);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    private void sendCompletioned(int arg3) {
        try {
            this.mReentrantLock.lock();
            if (this.mOnCompletionListener != null && arg3 >= this.mPlayLifeId) {
                this.mOnCompletionListener.onCompletion();
            }
        } catch (Throwable v0) {
            if (this.mReentrantLock.isLocked()) {
                this.mReentrantLock.unlock();
            }

            throw v0;
        }

        if (this.mReentrantLock.isLocked()) {
            this.mReentrantLock.unlock();
        }
    }

    private void sendErrorInfo(int arg4, int arg5) {
        try {
            this.mReentrantLock.lock();
            if (this.mOnErrorListener != null && arg5 >= this.mPlayLifeId) {
                IMediaPlayerClient.OnErrorListener v0_1 = this.mOnErrorListener;
                IMediaPlayerClient v1 = this.mWrapper;
                if (arg4 == 0) {
                    arg4 = -1048575;
                }

                v0_1.onError(v1, arg4, 0);
            }
        } catch (Throwable v0) {
            if (this.mReentrantLock.isLocked()) {
                this.mReentrantLock.unlock();
            }

            throw v0;
        }

        if (this.mReentrantLock.isLocked()) {
            this.mReentrantLock.unlock();
        }
    }

    private void sendSeekCompleted(int arg2) {
        if (!this.mSeekComplete && this.mOnSeekCompleteListener != null) {
            this.mSeekComplete = true;
            if (arg2 >= this.mPlayLifeId) {
                this.mOnSeekCompleteListener.onSeekComplete();
            }
        }
    }

    public void setCacheFile(String arg3, int arg4) {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setCacheFile(arg3, arg4);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setDataSource(Context arg2, Uri arg3) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {
        if (arg3 != null) {
            this.setDataSource(arg3.toString());
        }
    }

    public void setDataSource(String arg3) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {
        String v0 = arg3.toLowerCase(Locale.ENGLISH);
        this.mUri = (v0.startsWith("http://")) || (v0.startsWith("https://")) || (v0.startsWith("ftp://")) || (v0.startsWith("rtmp://")) || (v0.startsWith("rtmps://")) || (v0.startsWith("rtsp://")) || (v0.startsWith("rtsps://")) ? arg3 : "file://" + arg3;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setDataSource(this.mUri);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
    }

    public void setDataSource(Context context, Uri arg7, Map<String,String> params) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {
        if (arg7 != null) {
            this.setDataSource(context, arg7);
            if (params != null && params.size() != 0) {
                StringBuilder v1 = new StringBuilder();
                Iterator v2 = params.keySet().iterator();
                while (v2.hasNext()) {
                    Object v0 = v2.next();
                    v1.append(((String) v0)).append(":").append(params.get(v0)).append("\r\n");
                }

                this.mReadLock.lock();
                try {
                    if (this.isValid()) {
                        this.mPlayer.setStringOption(20, v1.toString());
                    }
                } catch (Throwable v0_1) {
                    this.mReadLock.unlock();
                    throw v0_1;
                }

                this.mReadLock.unlock();
            }
        }
    }

    public void setDisplay(SurfaceHolder surfaceHolder) {
        if (this.mSurfaceHolder != null) {
            this.mSurfaceHolder.removeCallback(this.mCallback);
        }

        this.mSurfaceHolder = surfaceHolder;
        Surface v0 = null;
        if (surfaceHolder != null) {
            this.mSurfaceHolder.addCallback(this.mCallback);
            v0 = this.mSurfaceHolder.getSurface();
        }

        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setVideoSurface(v0);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        this.updateSurfaceScreenOn();
    }

    public int setIntOption(int arg3, int arg4) {
        int v0 = -1;
        if (arg3 == 41) {
            AVResolver.HOST_MAX_CACHE_TIME = arg4;
            v0 = 0;
        } else {
            this.mReadLock.lock();
            try {
                if (this.isValid()) {
                    v0 = this.mPlayer.setIntOption(arg3, arg4);
                }
            } catch (Throwable v0_1) {
                this.mReadLock.unlock();
                throw v0_1;
            }

            this.mReadLock.unlock();
        }

        return v0;
    }

    public void setIsMute(boolean arg4) {
        int v0_1;
        int v2;
        com.ss.ttm.player.f v1;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v1 = this.mPlayer;
                v2 = 12;
                if (arg4) {
                    v0_1 = 1;
                } else {
                    v0_1 = 0;
                }
                v1.setIntOption(v2, v0_1);
            }
        } finally {
            this.mReadLock.unlock();
        }
    }

    public int setLongOption(int arg3, long arg4) {
        int v0 = -1;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v0 = this.mPlayer.setLongOption(arg3, arg4);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        return v0;
    }

    public void setLooping(boolean arg3) {
        int v0_1;
        com.ss.ttm.player.f v1;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v1 = this.mPlayer;
                if (arg3) {
                    v0_1 = 1;
                } else {
                    v0_1 = 0;
                }
                v1.setLooping(v0_1);
            }
        } finally {
            this.mReadLock.unlock();
        }
    }

    public void setOnBufferingUpdateListener(IMediaPlayerClient.OnBufferingUpdateListener arg5) {
        this.mOnBufferingUpdateListener = arg5;
        this.mListenerState |= 8;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setNotifyerState(this.mListenerState);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setOnCompletionListener(IMediaPlayerClient.OnCompletionListener arg5) {
        this.mOnCompletionListener = arg5;
        this.mListenerState |= 8192;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setNotifyerState(this.mListenerState);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setOnErrorListener(IMediaPlayerClient.OnErrorListener arg5) {
        this.mOnErrorListener = arg5;
        this.mListenerState |= 1;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setNotifyerState(this.mListenerState);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setOnInfoListener(IMediaPlayerClient.OnInfoListener arg5) {
        this.mOnInfoListener = arg5;
        this.mListenerState |= 1970;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setNotifyerState(this.mListenerState);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setOnLogListener$47ab1a9d(a arg1) {
        this.mLogListener$2f9df788 = arg1;
    }

    public void setOnPreparedListener(IMediaPlayerClient.OnPreparedListener arg5) {
        this.mOnPreparedListener = arg5;
        this.mListenerState |= 4;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setNotifyerState(this.mListenerState);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setOnSeekCompleteListener(IMediaPlayerClient.OnSeekCompleteListener arg5) {
        this.mOnSeekCompleteListener = arg5;
        this.mListenerState |= 4096;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setNotifyerState(this.mListenerState);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setOnVideoSizeChangedListener(IMediaPlayerClient.OnVideoSizeChangedListener arg5) {
        this.mOnVideoSizeChangedListener = arg5;
        this.mListenerState |= 64;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setNotifyerState(this.mListenerState);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setPanoVideoControlModel(int arg3) {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setIntOption(11, arg3);
            }
        } catch (Throwable throwable) {
            this.mReadLock.unlock();
            throw throwable;
        }

        this.mReadLock.unlock();
    }

    public void setScreenOnWhilePlaying(boolean arg3) {
        if (this.mScreenOnWhilePlaying != arg3) {
            if ((arg3) && this.mSurfaceHolder == null) {
                Log.w(TTPlayerClient.TAG, "setScreenOnWhilePlaying(true) is ineffective without a SurfaceHolder");
            }

            this.mScreenOnWhilePlaying = arg3;
            this.updateSurfaceScreenOn();
        }
    }

    public int setStringOption(int arg3, String arg4) {
        int v0 = -1;
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                v0 = this.mPlayer.setStringOption(arg3, arg4);
            }
        } catch (Throwable v0_1) {
            this.mReadLock.unlock();
            throw v0_1;
        }

        this.mReadLock.unlock();
        return v0;
    }

    public void setSurface(Surface arg3) {
        this.mReadLock.lock();
        try {
            if ((this.isValid()) && arg3 != this.mSurface) {
                this.mSurface = arg3;
                this.mPlayer.setVideoSurface(arg3);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    public void setVolume(float arg3, float arg4) {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.setVolume(arg3, arg4);
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
    }

    @SuppressLint(value = {"Wakelock"})
    public void setWakeMode(Context arg6, int arg7) {
        int v2;
        int v0;
        if (this.mWakeLock != null) {
            if (this.mWakeLock.isHeld()) {
                v0 = 1;
                this.mWakeLock.release();
            } else {
                v0 = 0;
            }

            this.mWakeLock = null;
            v2 = v0;
        } else {
            v2 = 0;
        }

        this.mWakeLock = ((PowerManager) arg6.getSystemService(Context.POWER_SERVICE)).newWakeLock(536870912 | arg7, p.class.getName());
        this.mWakeLock.setReferenceCounted(false);
        if (v2 != 0) {
            this.mWakeLock.acquire();
        }
    }

    public void start() {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mErrorCode = 0;
                this.mPlayer.start();
                this.updateLifeId();
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
        this.stayAwake(true);
    }

    @SuppressLint(value = {"Wakelock"})
    private void stayAwake(boolean arg2) {
        if (this.mWakeLock != null) {
            if (arg2 && !this.mWakeLock.isHeld()) {
                this.mWakeLock.acquire();
            } else if (arg2) {
            } else if (!this.mWakeLock.isHeld()) {
            } else {
                this.mWakeLock.release();
            }
        }

        label_8:
        this.mStayAwake = arg2;
        this.updateSurfaceScreenOn();
    }

    public void stop() {
        this.mReadLock.lock();
        try {
            if (this.isValid()) {
                this.mPlayer.stop();
            }
        } catch (Throwable v0) {
            this.mReadLock.unlock();
            throw v0;
        }

        this.mReadLock.unlock();
        this.stayAwake(false);
    }

    public void takeScreenshot$61a88cc1(ScreenshotListener transformation) {
        if (this.mPlayer != null && transformation != null) {
            this.mListenerState |= 32768;
            this.mReadLock.lock();
            try {
                if (this.isValid()) {
                    this.mPlayer.setNotifyerState(this.mListenerState);
                    this.mPlayer.setOnScreenshotListener(transformation);
                    this.mPlayer.takeScreenshot();
                }
            } catch (Throwable throwable) {
                this.mReadLock.unlock();
                throw throwable;
            }
            this.mReadLock.unlock();
        }
    }

    protected void updateLifeId() {
        try {
            this.mReentrantLock.lock();
            this.mPlayLifeId = this.mPlayer.l();
        } catch (Throwable throwable) {
            if (this.mReentrantLock.isLocked()) {
                this.mReentrantLock.unlock();
            }
            throw throwable;
        }

        if (this.mReentrantLock.isLocked()) {
            this.mReentrantLock.unlock();
        }
    }

    public void updateSurfaceScreenOn() {
        if (this.mSurfaceHolder != null) {
            boolean keepScreenOn = this.mScreenOnWhilePlaying && this.mStayAwake;
            mSurfaceHolder.setKeepScreenOn(keepScreenOn);
        }
    }
}

